import * as Cookies from 'js-cookie'
const host = location.hostname

const COOKIE_PREFIX = 'ikf_'
const domain = host == 'localhost' ? 'localhost' : '.99496.com'

const keyWithPrefix = (key) => {
  return `${COOKIE_PREFIX}${key || ''}`
}

export default class CookieStore {
  static set(key, value, options) {
    key = keyWithPrefix(key)
    value = value !== undefined ? value : ''
    options = Object.assign({path: '/', expires: 7, domain}, options)
    Cookies.set(key, value, options)
  }

  static get(key) {
    key = keyWithPrefix(key)
    return Cookies.get(key, {domain})
  }

  static getJSON(key) {
    key = keyWithPrefix(key)
    return Cookies.getJSON(key)
  }

  static remove(key) {
    key = keyWithPrefix(key)
    Cookies.remove(key, {path: '/', domain})
  }

  static getRaw(key) {
    return Cookies.get(key)
  }

  static setRaw(key, value, options) {
    Cookies.set(key, value, options)
  }
}
